[//登陆模版

async function( kuo,Context,context){
    Context.headers["content-type"] = 'application/json; charset=UTF-8';
    let LANG = this.LANG();
    let $_SESSION = await Mem.Get("session/"+kuo.sessionid);
    let $DATA = Object.assign({},this.$DATA);
    let $_POST = kuo.post;
    let $safhash1 = 'adminfind/'+kuo.ip;
    let $jishu = await Mem.Get($safhash1);
    if($jishu && $jishu >= 3){
        $DATA.code =-1;
        $DATA.msg = LANG["Saft_error"];
        Context.body = JSON.stringify($DATA);
        await Mem.Add($safhash1,1,this.SaftTime);
        return ;
    }

    if(! $_POST['username'] || $_POST['username'].length < 2 || $_POST['username'].length > 32 ){
        $DATA.code =-2;
        $DATA.msg = LANG["username_error"];
        Context.body = JSON.stringify($DATA);
        await Mem.Add($safhash1,1,this.SaftTime);
        return ;
    }

    if(! $_POST['password'] || $_POST['password'].length < 6 || $_POST['password'].length > 32 ){
        $DATA.code =-3;
        $DATA.msg = LANG["password_error"];
        Context.body = JSON.stringify($DATA);
        await Mem.Add($safhash1,1,this.SaftTime);
        return ;
    }
   
    if(!$_SESSION  || !$_POST['vcode'] || $_SESSION.code == ""  || $_POST['vcode'] != $_SESSION.code){
        $DATA.code =-4;
        $DATA.msg = LANG["vcode_error"];
        Context.body = JSON.stringify($DATA);
        await Mem.Add($safhash1,1,this.SaftTime);
        return ;
    }
    let $DB = await db('admin');
    let fan = await $DB.Where({account:$_POST['username']}).Find();
    if(!fan){
        $DATA.code =-5;
        $DATA.msg = LANG["username_error"];
        Context.body = JSON.stringify($DATA);
        await Mem.Add($safhash1,1,this.SaftTime);
        return ;
    }
    if( fan['off'] != 1 ){
        $DATA.code =-6;
        $DATA.msg =  LANG["admin_login_error"];
        Context.body = JSON.stringify($DATA);
        await Mem.Add($safhash1,1,this.SaftTime);
        return ;
    }

    if( fan['password'] != Kuomm($_POST['password']) ){
        $DATA.code =-7;
        $DATA.msg = LANG["admin_login_error"];
        Context.body = JSON.stringify($DATA);
        await Mem.Add($safhash1,1,this.SaftTime);
        return ;
    }
    await  Mem.Del($safhash1);
    let $iphash = 'adminip/'+fan['id'];
    await Mem.Put("session/"+kuo.sessionid,{adminid:fan['id'],groups:fan['groups'],account:fan['account']},Expiredseconds);
    await Mem.Set($iphash,kuo.ip);
    await $DB.Where({id:fan['id']}).Update({ip:kuo.ip,atime:Mode("Tools").Time(),sessionid:kuo.sessionid});
    await Adminid(fan['id'],1);
    await Kuolog('adminlog',fan['id'],0,"",kuo.func_,kuo.class,kuo.ip);
    let $hash = 'safetoken/'+fan['id'];
    $DATA.token = Mode("Tools").Uuid();
    await Mem.Set($hash,$DATA.token);
    $DATA.code =1;
    let adminmen = await  Kuo_admin.Groupscaidan(fan['groups'],kuo.sessionid);
    let admingroupsname = await  Kuo_admin.Groupsid(fan['groups']);
    $DATA.data ={
        adminmen:adminmen,
        admininame:fan['account'],
        admingroupsname:admingroupsname,
    };

    Context.body = JSON.stringify($DATA);
}

]